package com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck;

import com.personal.gateway.custom.customException.ConfigurationOptionCheckException;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeListString;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * @author BigHead
 * @date 2022/1/11 10:57
 * @description ParameterCheckString
 */
public class ParameterCheckListString extends AbstractParameterCheck<List<String>, ConfigurationTypeListString> {

    public static final String LIST_SPLIT_KEY = ",";

    @Override
    public List<String> abstractCheckValue(ConfigurationOption<List<String>, ConfigurationTypeListString> configurationOption, String value) {
        if (StringUtils.isNotEmpty(value)) {
            if (value.split(LIST_SPLIT_KEY).length < 1) {
                throw new ConfigurationOptionCheckException(value, configurationOption);
            } else {
                return Arrays.asList(
                        value.split(LIST_SPLIT_KEY)
                );
            }
        }
        return null;
    }
}
